<template>
  <div class="userManagement-container">
    <el-row :gutter="20" class="index-container">
      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
        <el-card shadow="never">
          <div slot="header">
            <span>用户操作审计图</span>
          </div>
          <vab-chart
            :autoresize="true"
            theme="vab-echarts-theme"
            :options="userAudit"
          />
        </el-card>
      </el-col>
    </el-row>
    <vab-query-form>
      <vab-query-form-right-panel :span="24">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.name"
              placeholder="请输入用户名"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      :height="height"
      :element-loading-text="elementLoadingText"
    >
      <el-table-column show-overflow-tooltip prop="realname" label="用户名">
        <template slot-scope="scope">
          <el-popover trigger="click" placement="top" style="left: auto">
            <vab-chart
              v-loading="pieload"
              :autoresize="true"
              theme="vab-echarts-theme"
              :options="personal"
            />
            <div slot="reference">
              <el-tag size="medium" @click="handpie(scope.row)">
                {{ scope.row.realname }}
              </el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="videoCount"
        label="视频数量"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="textEditTimes"
        label="文本修改次数"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="videoEditTimes"
        label="视频修改次数"
      ></el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :page-size="queryForm.pageSize"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
    <edit ref="edit" @fetch-data="fetchData"></edit>
  </div>
</template>

<script>
  import Edit from './components/UserManagementEdit'
  import VabChart from '@/plugins/echarts'
  import { userAuditgetList, videoMsg } from '@/api/audit'
  export default {
    name: 'UserAudit',
    components: { VabChart, Edit },
    data() {
      return {
        pieload: false,
        selectRows: '',
        userAudit: {
          grid: {
            top: '4%',
            left: '2%',
            right: '4%',
            bottom: '0%',
            containLabel: true,
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow',
            },
          },
          xAxis: [
            {
              type: 'category',
              /*boundaryGap: false,*/
              data: [],
              axisTick: {
                alignWithLabel: true,
              },
            },
          ],
          yAxis: [
            {
              type: 'value',
              minInterval: 1,
            },
          ],
          series: [
            {
              name: '视频数量',
              type: 'bar',
              emphasis: {
                focus: 'series',
              },
              data: [],
            },
            {
              name: '文本修改次数',
              type: 'bar',
              data: [],
            },
            {
              name: '视频修改次数',
              type: 'bar',
              data: [],
            },
          ],
        },
        personal: {
          grid: {
            top: '4%',
            left: '2%',
            right: '4%',
            bottom: '0%',
            containLabel: true,
          },
          tooltip: {
            trigger: 'item',
          },
          series: [
            {
              type: 'pie',
              data: [
                { value: 10, name: '视频数量' },
                { value: 16, name: '文本修改次数' },
                { value: 16, name: '视频修改次数' },
              ],
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
              },
            },
          ],
        },
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        elementLoadingText: '正在加载...',
        queryForm: {
          name: '',
          pageNo: 1,
          pageSize: 10,
        },
        payid: 0,
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.fetchData()
    },
    methods: {
      setSelectRows(val) {
        this.selectRows = val
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      queryData() {
        this.fetchData()
      },
      handpie(val) {
        this.pieload = true
        this.personal.series[0].data[0].value = val.videoCount
        this.personal.series[0].data[1].value = val.textEditTimes
        this.personal.series[0].data[2].value = val.videoEditTimes
        setTimeout(() => {
          this.pieload = false
        }, 300)
      },
      async fetchData() {
        this.listLoading = true
        const query = await userAuditgetList(this.queryForm)
        let data = query.data
        this.list = data.data
        this.total = data.totalResults
        let temp = []
        let myx = []
        let vsum = []
        let tedit = []
        let vedit = []
        temp = data.data
        for (let i = 0; i < temp.length; i++) {
          myx.push(temp[i].realname)
          vsum.push(temp[i].videoCount)
          tedit.push(temp[i].textEditTimes)
          vedit.push(temp[i].videoEditTimes)
        }
        this.userAudit.xAxis[0].data = myx
        this.userAudit.series[0].data = vsum
        this.userAudit.series[1].data = tedit
        this.userAudit.series[2].data = vedit
        setTimeout(() => {
          this.listLoading = false
        }, 300)
      },
    },
  }
</script>
<style lang="scss" scoped>
  .index-container {
    padding: 0 !important;
    margin: 0 !important;

    ::v-deep {
      .el-card__body {
        .echarts {
          width: 100%;
          height: 115px;
        }
      }
    }

    .card {
      ::v-deep {
        .el-card__body {
          .echarts {
            width: 100%;
            height: 305px;
          }
        }
      }
    }

    .bottom {
      padding-top: 20px;
      margin-top: 5px;
      color: #595959;
      text-align: left;
      border-top: 1px solid $base-border-color;
    }

    .icon-panel {
      height: 117px;
      text-align: center;
      cursor: pointer;

      svg {
        font-size: 40px;
      }

      p {
        margin-top: 10px;
      }
    }

    .bottom-btn {
      button {
        margin: 5px 10px 15px 0;
      }
    }
  }
</style>
